package com.platform.controller;

import com.platform.annotation.SysOptionLog;
import com.platform.entity.IncomeCoinEntity;
import com.platform.service.IncomeCoinService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 运动币记录表Controller
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2019-02-20 19:49:17
 */
@RestController
@RequestMapping("incomecoin")
public class IncomeCoinController {
    @Autowired
    private IncomeCoinService incomeCoinService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("incomecoin:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<IncomeCoinEntity> incomecoinList = incomeCoinService.queryList(query);
        int total = incomeCoinService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(incomecoinList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("incomecoin:info")
    public R info(@PathVariable("id") Long id) {
        IncomeCoinEntity incomecoin = incomeCoinService.queryObject(id);

        return R.ok().put("incomecoin", incomecoin);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("incomecoin:save")
    @SysOptionLog("添加用户运动链收益记录")
    public R save_coin(@RequestBody IncomeCoinEntity incomecoin) {
        incomeCoinService.save(incomecoin);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("incomecoin:update")
    @SysOptionLog("修改用户运动链收益记录")
    public R update_coin(@RequestBody IncomeCoinEntity incomecoin) {
        incomeCoinService.update(incomecoin);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("incomecoin:delete")
//    @SysOptionLog("删除用户运动链收益记录")
    public R delete_coin(@RequestBody Long[] ids) {
        incomeCoinService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<IncomeCoinEntity> list = incomeCoinService.queryList(params);

        return R.ok().put("list", list);
    }

    /**
     * @Description: 查询兑换总数
     * @Author: LiFangzhou
     * @Date: 2019/3/30 14:39
     * @Param: [params]
     * @Return: com.platform.utils.R
     * @Exception:
     */
    @RequestMapping("/coins")
    @ResponseBody
    public R queryCoins(@RequestParam Map<String, Object> params) {
        if(params.get("name")==""&&params.get("mobile")==""&&params.get("uid")==""&&params.get("type")==""){
            return R.ok().put("coins",0);
        }
        BigDecimal coins = incomeCoinService.queryCoins(params);

        return R.ok().put("coins",coins);
    }
}
